/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui.cd;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.apache.log4j.Logger;

import who.tmap.services.TextureService;

public class TableComboBoxRendererPattern extends JLabel 
										   implements TableCellRenderer {
	
    private static Logger logger = Logger.getLogger(TableComboBoxRendererPattern.class);	
	
	private static final TextureService textureHelper =TextureService.getInstance();
	
	public TableComboBoxRendererPattern() {
		super();
		setOpaque(true);
		setHorizontalAlignment(LEFT);
		setVerticalAlignment(CENTER);
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

		if ( value != null ) {
			int selectedIndex =((Integer)value).intValue();
	
			setFont( table.getFont() );
			ImageIcon icon = textureHelper.getImageIcons()[ selectedIndex ];
			setIcon(icon);
			setText( textureHelper.getPatternNames()[ selectedIndex ] );

		}

		return this;
	}
	

}
